const axios = require('axios');

// 测试根据openid查询用户信息
async function testOpenidQuery() {
  try {
    // 先创建一个测试用户
    const createUserResponse = await axios.post('http://localhost:3000/api/users', {
      username: 'test_openid_user',
      password_hash: 'test_password',
      nickname: 'Test User',
      openid: 'test_openid_12345'
    });
    
    console.log('Created user:', createUserResponse.data);
    
    // 根据openid查询用户
    const queryResponse = await axios.get('http://localhost:3000/api/users/openid/test_openid_12345');
    
    console.log('User found by openid:', queryResponse.data);
    
    // 清理：删除测试用户
    await axios.delete(`http://localhost:3000/api/users/${createUserResponse.data.id}`);
    
    console.log('Test completed successfully');
  } catch (error) {
    console.error('Test failed:', error.response ? error.response.data : error.message);
  }
}

testOpenidQuery();
